﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Store.Bll;
using Store.Model.Models;
using Microsoft.AspNetCore.Cors;
using Newtonsoft.Json;

namespace Store.Server.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [EnableCors("any")]
    public class UsersController : ControllerBase
    {
        private readonly UsersBll  bll;
        public UsersController(UsersBll bl)
        {
            bll = bl;
        }

        [HttpGet]
        public IActionResult GetUser(string id, string name, int pageIndex, int pageSize)//显示
        {
            int total;
            List<User> str = bll.GetUsers(id,name,pageIndex,pageSize,out total);
            return Ok( new { data=str,total=total});
        }
        [HttpDelete]
        public int Delete(int id)
        {
            return bll.Delete(id);
        }
        [HttpPut]
        public int Update(User user)
        {
            fantian(user.UserId);
            var str = bll.Update(user);
            return str;
        }
        [HttpGet]
        public User fantian(int id)
        {
            return bll.fantian(id);
        }
        [HttpPost]
        public int Add(User user)
        {
            return bll.Add(user);
        }
        [HttpGet]
        public IActionResult GetUsers2(string userName, string userAccount, string userPrice, string userCount, string userAvg, int pageIndex=1, int pageSize=3)//条件查询
        {
            int total;
            List<User> str =  bll.GetUsers2(userName, userAccount, userPrice, userCount, userAvg, pageIndex, pageSize, out total);
           
            return Ok(new { data = str, total = total });
        }
    }
}
